# -*- coding: utf-8 -*-

# Copyright: (c) 2007 by Jarek Zgoda, <jzgoda@o2.pl>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Steet, Fifth Floor, Boston, MA  02111-1307, USA.

"""Common classes and exception hierarchies"""

__revision__ = '$Id: common.py 29 2007-04-24 07:59:58Z jarek.zgoda $'

import time
import md5

class AudioscrobblerError(Exception): pass

class AudioscrobblerServiceError(AudioscrobblerError): pass

class AudioscrobblerAuthorizationError(AudioscrobblerError): pass

class ClientError(Exception): pass

class ClientVersionMismatchError(ClientError): pass

def get_challenge_string():
    """
    This function mimics closely the operation of original LastFM client,
    although it is not required to do so.
    """
    return str(int(time.time()))

def get_challenge_hash(password, challenge):
    """
    Create a hash of password and challenge string to be used in XML-RPC calls.
    """
    return md5.new('%s%s' % (password, challenge)).hexdigest()

WS_URL = 'ws.audioscrobbler.com'
WSDEV_URL = 'wsdev.audioscrobbler.com'

